import { createRouter, RouteRecordRaw, createWebHistory } from "vue-router";
import autoRoutes from "virtual:generated-pages";

console.log("autoRoutes", autoRoutes);

let routes: RouteRecordRaw[] = [
  {
    path: "/404",
    component: () => import("@/views/404.vue"),
  },
  {
    path: "/:pathMatch(.*)*",
    redirect: "/",
  },
  {
    path: "/",
    name: "index",
    component: import("@/views/login.vue"),
  },
];

// 需要修改参数,在autoRoutes上拓展
routes.push(...autoRoutes);

// 重写传参路由
let replacePath: { before: string; after: string }[] = [];

routes = routes.map((item) => {
  let exit = replacePath.find((subItem) => {
    return item.path == subItem.before;
  });
  if (exit) {
    item.path = exit.after;
  }
  return item;
});

const router = createRouter({
  // createWebHistory("/your-prefix/"), // 设置前缀
  history: createWebHistory(),
  routes,
});

export default router;
